package pl.druminski.robinhood.view;

import java.awt.AWTException;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.util.logging.Logger;
import pl.druminski.robinhood.model.Data;

/**
 * @author Łukasz Drumiński
 * 
 */
public class Tray
{

    public TrayIcon trayIcon;
    private PopupMenu popup;
    public MenuItem itemExit;
    public MenuItem itemOptions;
    public MenuItem itemRun;
    private Data data;

    public Tray(Data data)
    {
        if (SystemTray.isSupported())
        {
            this.data = data;

            SystemTray tray = SystemTray.getSystemTray();
           
            //tworzenie menu dla ikony w tray
            popup = new PopupMenu();
            itemExit = new MenuItem("Exit");
            itemOptions = new MenuItem("Opcje");
            itemRun = new MenuItem("Wyklikaj");

            popup.add(itemRun);
            popup.add(itemOptions);
            popup.add(itemExit);

            trayIcon = new TrayIcon(data.getIcon().getImage(), "Robin Hood", popup);
            trayIcon.setImageAutoSize(true);

            try
            {
                tray.add(trayIcon);
            } catch (AWTException e)
            {
                Logger.getLogger("RobinHoodLog").warning("TrayIcon could not be added.");
            }

        } else
        {
            Logger.getLogger("RobinHoodLog").warning("System tray is not supported");
        }
    }

    public void setRun(boolean enable)
    {
        this.itemRun.setEnabled(enable);
    }
}
